package  
{
	import com.bumpslide.util.Delegate;
	import com.bumpslide.ui.Applet;
	import com.bumpslide.ui.Box;
	import com.bumpslide.ui.behavior.DragBehavior;

	import flash.display.Sprite;
	import flash.geom.Rectangle;

	/**
	 * Drag Example 2 - Basic Drag (constrained)
	 * 
	 * This example shows how to constrain drag behavior by passing a Rectangle
	 * into the init method.  It also demonstrates that dragging works even 
	 * inside objects that have been transformed or rotated.
	 * 
	 * March 2010, added test for transformed drag targets.
	 * 
	 * @author David Knape
	 * @mxmlc -sp+=../../classes -default-background-color 0xeeeeee -default-frame-rate 60 -debug
	 */
	public class DragExample02 extends Applet 
	{
		
		private var container:Sprite;
		private var background:Box;
		private var box:Box;
		
		override protected function addChildren():void
		{
			super.addChildren();
			
			// container for background and box
			container = new Sprite();
			container.rotation = 20;
			container.x = container.y = 100;
			addChild(container);	
			
			// background (represents drag boundary)
			background = new Box(0xdddddd, 300, 100, 0, 0, 0, 0, 0x880000);
			container.addChild(background);
			
			// the draggable box
			box = new Box(0x000088, 20, 20);
			box.centerOrigin = true;
			box.buttonMode = true;
			// test for dragging content that has been transformed
			box.scaleX = 1.5; 
			box.scaleY = 2; 
			box.rotation = 45;
			container.addChild(box);
			
			// make the box draggable and constrain to the background 	
			DragBehavior.init(box, new Rectangle(0, 0, 300, 100));
			
			Delegate.onEnterFrame(rotateBox);
		}
		
		private function rotateBox() : void {
			box.rotation++;
		}
		
		
	}
}
